<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class CI_Email_subscription_entity{
	var $id = 0;
	var $subject = "";
	var $body = "";
	var $sent = "";
	var $created_date = 0;
	var $last_sent_date = 0;
	var $type = "";
	var $sms_content = "";
	
	function __destruct() {}
	function __construct() {}
    
	function init($cmd, $input)
	{
		$ci=& get_instance();
		
		if($cmd == 'id')
		{
			$result = $ci->db->where('id',$input)->get(TBL_EMAIL_SUBS)->result();
		}
		else
		{
			return false;
		}
		
		if( !empty($result) )
		{
			$this->id = $result[0]->id;
			$this->subject = $result[0]->subject;
			$this->body = $result[0]->body;
			$this->sent = $result[0]->sent;
			$this->created_date = $result[0]->created_date;
			$this->last_sent_date = $result[0]->last_sent_date;
			$this->type = $result[0]->type;
			$this->sms_content = $result[0]->sms_content;
			
			return $this;
		}
		return false;
	}
	
	function setSubject($input){ $this->subject=$input; }
	function setBody($input){ $this->body=$input;}
	function setSent($input){ $this->sent=$input; }
	function setCreatedDate($input){ $this->created_date=$input;}
	function setLastSentDate($input){ $this->last_sent_date=$input; }
	function setType($input){ $this->type=$input; }
	function setSmsContent($input){ $this->sms_content=$input; }
	
	function getId(){ return $this->id; }
	function getSubject(){ return $this->subject; }
	function getBody(){ return $this->body;}
	function getSent(){ return $this->sent;}
	function getCreatedDate(){ return $this->created_date;}
	function getLastSentDate(){ return $this->last_sent_date;}
	function getType(){ return $this->type; }
	function getSmsContent(){ return $this->sms_content; }
	
	function update()
	{
		$ci=& get_instance();
		 
		$ci->db->set('subject', $this->subject);
		$ci->db->set('body', $this->body);
		$ci->db->set('sent', $this->sent);
		$ci->db->set('created_date', $this->created_date);
		$ci->db->set('last_sent_date', $this->last_sent_date);
		$ci->db->set('type', $this->type);
		$ci->db->set('sms_content', $this->sms_content);
		
		$ci->db->where('id', $this->id)->update(TBL_EMAIL_SUBS);
	}
	
	function createNewEntity(){
		$ci=& get_instance();
		
		$ci->db->set('created_date',time());
		$ci->db->insert(TBL_EMAIL_SUBS);
		
		return $ci->db->insert_id();
	}
	
	
}
